#include "UIGameOver.h"
#include "Common.h"
#include "GameScene.h"

UIGameOver::UIGameOver()
{

}

UIGameOver::~UIGameOver()
{

}

UIGameOver* UIGameOver::create()
{
	UIGameOver* p = new UIGameOver();
	if (p && p->init())
	{
		p->autorelease();
		return p;
	}

	CC_SAFE_DELETE(p);
	return p;
}

bool UIGameOver::init()
{
	CCLayer::init();
	bool bRet = false;
	do
	{
		UILayer* pUILayer = UILayer::create();
		CC_BREAK_IF(!pUILayer);

		UILayout* pRoot = (UILayout*)GUIReader::shareReader()->widgetFromJsonFile("ui/gameover/gameover_1.json");
		pRoot->setSize(getContentSize());
		pUILayer->addWidget(pRoot);
		addChild(pUILayer);

		registerTouchEvent(UIGameOver, EUIGT_share);
		registerTouchEvent(UIGameOver, EUIGT_rock);
		registerTouchEvent(UIGameOver, EUIGT_retry);
		registerTouchEvent(UIGameOver, EUIGT_more);

		bRet = true;
	}while (0);

	return  bRet;
}


void UIGameOver::onEnter()
{
	CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
	CCLayer::onEnter();
}

void UIGameOver::onExit()
{
	CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);

	CCLayer::onExit();
}

void UIGameOver::on_EUIGT_share(CCObject* pSender, TouchEventType eType)
{
	checkTouchEventTypeIsEnd(eType);

}

void UIGameOver::on_EUIGT_more(CCObject* pSender, TouchEventType eType)
{
	checkTouchEventTypeIsEnd(eType);

}

void UIGameOver::on_EUIGT_retry(CCObject* pSender, TouchEventType eType)
{
	checkTouchEventTypeIsEnd(eType);
	CCDirector::sharedDirector()->replaceScene(CCTransitionProgressOutIn::create(1, GameScene::create()));
}

void UIGameOver::on_EUIGT_rock(CCObject* pSender, TouchEventType eType)
{
	checkTouchEventTypeIsEnd(eType);

}



